package com.aiyige.page.publish;


import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.utils.UIHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class CommonTipDialog extends DialogFragment {
    Unbinder unbinder;
    String message;
    @BindView(R.id.contentTv)
    TextView contentTv;

    public CommonTipDialog() {
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static CommonTipDialog newInstance(String message) {
        CommonTipDialog fragment = new CommonTipDialog();
        fragment.setStyle(STYLE_NORMAL, R.style.CommonDialogTheme);
        fragment.setMessage(message);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.common_tip_dialog, container, false);
        unbinder = ButterKnife.bind(this, view);
        contentTv.setText(message);
        contentTv.setMovementMethod(ScrollingMovementMethod.getInstance());
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        Window window = getDialog().getWindow();
        if (window != null) {
            WindowManager.LayoutParams layoutParams = window.getAttributes();
            layoutParams.width = Resources.getSystem().getDisplayMetrics().widthPixels - UIHelper.dip2px(50);
            layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
            window.setAttributes(layoutParams);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.okBtn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.okBtn:
                dismiss();
                break;
        }
    }
}
